package model;

import java.util.HashMap;
import java.util.Hashtable;

public class Node extends AccessPoint{
	
	private Hashtable<String, Double> distanceToAccessPoint;

	public Node(String name) {
		super(name);
	}
	
	public  Node(int x, int y, String name) {
		super(x, y,name);
	}
	
	public double getApsoluteDistance(int x, int y){
		return Math.sqrt(Math.pow(this.xCoordinate - x, 2) + Math.pow(this.yCoordinate - y, 2));
	}
	
	public double getApsoluteDistance(AccessPoint ap){
		return getApsoluteDistance(ap.xCoordinate, ap.yCoordinate);
	}
	
	public double getRelativeDistance(Node node){
		double cumulativeDiff = 0;
		int machedAPs = 0;
		for(int i = 0; i < distanceToAccessPoint.size(); i++){
			String curName = distanceToAccessPoint.keys().nextElement();
			if(node.distanceToAccessPoint.containsKey(curName)){
				cumulativeDiff += node.distanceToAccessPoint.get(curName);
				machedAPs++;
			}
		}
		
		return cumulativeDiff/machedAPs;
	}
	
	
	public void appointAP(AccessPoint ap){
		double distance = getApsoluteDistance(ap);
		distanceToAccessPoint.put(ap.getName(), distance);
	}
	
	
}
